Conditional Comments and Conditional Compilation

Conditional Comments

Conditional comments are conditional statements interpreted by Microsoft Internet Explorer versions 5 through 9 in HTML source code.

<!--[if IE]> <!--[if IE 5]><![endif]--> <!--[if IE 6]><![endif]--> <!--[if IE 7]><![endif]--> <!--[if IE 8]><![endif]--> <!--[if IE 9]><![endif]--> <![endif]-->

Reference: Wikipedia

Conditional Compilation

Starting with Internet Explorer 4, there exists a similar proprietary mechanism for adding conditional comments within JScript, known as conditional compilation.

<script type="text/jscript"> /*@cc_on @if (@_jscript_version == 11) document.write("You are using IE11 with an older document mode"); @elif (@_jscript_version == 10) document.write("You are using IE10"); @elif (@_jscript_version == 9) document.write("You are using IE9"); @elif (@_jscript_version == 5.8) document.write("You are using IE8"); @elif (@_jscript_version == 5.7) document.write("You are using IE" + (!window.XMLHttpRequest ? 6 : 7)); @elif (@_jscript_version == 5.6) document.write("You are using IE6"); @elif (@_jscript_version == 5.5) document.write("You are using IE5.5"); @elif (@_jscript_version < 5.5) document.write("You are using a version older than IE5.5"); @else document.write("You are using an unknown version of IE"); @end @*/ </script>

Reference: Wikipedia

Testing

You can test your browser here.

Conditional Comments - Test Results

BrowserResultNotes
Internet Explorer 1N/AUntested
Internet Explorer 2FailInternet Explorer 2 doesn't support Conditional Comments.
Internet Explorer 3FailInternet Explorer 3 doesn't support Conditional Comments.
Internet Explorer 4FailInternet Explorer 4 doesn't support Conditional Comments.
Internet Explorer 5Pass
Internet Explorer 5.5Pass
Internet Explorer 6Pass
Internet Explorer 7Pass
Internet Explorer 8Pass
Internet Explorer 9Pass
Internet Explorer 10FailInternet Explorer doesn't support Conditional Comments except in Compatibility Mode where it appears as Internet Explorer 7.
Internet Explorer 11FailInternet Explorer 11 doesn't support Conditional Formatting except in Compatibility Mode when it appears as Internet Explorer 7.

Conditional Compilation - Test Results

BrowserResultNotes
Internet Explorer 1N/AUntested
Internet Explorer 2FailInternet Explorer 2 doesn't support JScript.
Internet Explorer 3FailInternet Explorer 3 doesn't support Conditional Compilation.
Internet Explorer 4PassJScript version identified as 3.01.
Internet Explorer 5PassJScript version identified as 5.1.
Internet Explorer 5.5Pass
Internet Explorer 6Pass
Internet Explorer 7Pass
Internet Explorer 8Pass
Internet Explorer 9Pass
Internet Explorer 10PassJScript version is identified as 10 in Standard Mode and Compatibility Mode.
Internet Explorer 11FailConditional Composition only works in Compatibility Mode where the JScript version is identified as 11.

Test Conditions

Browser NameFull VersionPlatform
Internet Explorer 1N/AN/AN/A
Internet Explorer 2Microsoft Internet Explorer for Windows NT Version 2.0 (Build 1381)
Microsoft Windows NT Workstation 4.0 with Microsoft Internet Explorer

Microsoft Windows NT, 4.00.1381, IE 4.0.4.72.3612.1713

Internet Explorer 3Microsoft Internet Explorer Version 3.02 (4.70.1300)
Microsoft Windows NT Workstation 4.0 with Microsoft Internet Explorer

Microsoft Windows NT, 4.00.1381, IE 4.0.4.72.3612.1713

Internet Explorer 4
Microsoft Internet Explorer 4.0

Version: 4.72.3612.1713, Update Versions: SP2;3283

Microsoft Windows NT Workstation 4.0 with Microsoft Internet Explorer

Microsoft Windows NT, 4.00.1381, IE 4.0.4.72.3612.1713

Internet Explorer 5
Microsoft Internet Explorer 5

Version: 5.00.3314.2101, Update Versions: SP2

Microsoft Windows NT Workstation 4.0 with Microsoft Internet Explorer

Microsoft Windows NT, 4.00.1381, IE 5.5.00.3314.2101

Internet Explorer 5.5
Microsoft Internet Explorer

Version: 5.50.4807.2300, Update Versions: SP2

Microsoft Windows NT Workstation 4.0 with Microsoft Internet Explorer

Microsoft Windows NT, 4.00.1381, IE 5.5.50.4807.2300

Internet Explorer 6
Microsoft Internet Explorer

Version: 6.0.2600.0000

Microsoft Windows NT Workstation 4.0 with Microsoft Internet Explorer

Microsoft Windows NT, 4.00.1381, IE 5.6.0.2600.0000

Internet Explorer 7
Windows Internet Explorer 7

Version: 7.0.5730.13

Microsoft Windows XP Professional

Version 2002, Service Pack 3

Internet Explorer 8
Windows Internet Explorer 8

Version: 8.0.7601.17514

Windows 7 Ultimate

Service Pack 1

Internet Explorer 9
Windows Internet Explorer 9

Version: 9.0.8112.16421, Update Versions: 9.0.41 (KB3078071)

Windows 7 Ultimate

Service Pack 1

Internet Explorer 10
Internet Explorer 10

Version 10.0.9200.17457, Update Versions: 10.0.30

Windows 7 Ultimate

Service Pack 1

Internet Explorer 11
Internet Explorer 11

Version: 11.0.9600.17843, Update Versions: 11.0.20 (KB3058515)

Windows 7 Ultimate

Service Pack 1